package thread;

public class SyncDemo5 {
    public static void main(String[] args) {
        //Coo c = new Coo();
        Thread t1 = new Thread(Coo::methodA);
        Thread t2 = new Thread(Coo::methodB);
        t1.start();
        t2.start();

    }
}

class  Coo{
    public static synchronized void methodA(){
        try {
            Thread t = Thread.currentThread();
            System.out.println(t.getName()+"正在执行A方法");
            Thread.sleep(3000);
            System.out.println(t.getName()+"A方法执行完毕");
        } catch (InterruptedException e) {
        }
    }
    public static void methodB(){
        synchronized (Coo.class){
            try {
                Thread t = Thread.currentThread();
                System.out.println(t.getName()+"正在执行B方法");
                Thread.sleep(3000);
                System.out.println(t.getName()+"B方法执行完毕");
            } catch (InterruptedException e) {
            }
        }
    }
}